package org.example.manager.Impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.example.manager.LinkGroupManager;
import org.example.mapper.LinkGroupMapper;
import org.example.model.LinkGroupDO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: 谢超
 * @date: 2023/8/15 14:28
 */
@Component
public class LinkGroupManagerImpl implements LinkGroupManager {

    @Resource
    private LinkGroupMapper linkGroupMapper;

    @Override
    public int addGroup(LinkGroupDO linkGroupDO) {
        return linkGroupMapper.insert(linkGroupDO);
    }

    @Override
    public int delGroup(long groupId, long accountNo) {
        return linkGroupMapper.delete(Wrappers.lambdaQuery(LinkGroupDO.class).eq(LinkGroupDO::getId, groupId).eq(LinkGroupDO::getAccountNo, accountNo));
    }

    @Override
    public LinkGroupDO getGroupDetails(long groupId, long accountNo) {
        return linkGroupMapper.selectOne(Wrappers.lambdaQuery(LinkGroupDO.class).eq(LinkGroupDO::getId, groupId).eq(LinkGroupDO::getAccountNo, accountNo));
    }

    @Override
    public List<LinkGroupDO> getAllGroup(long accountNo) {
        return linkGroupMapper.selectList(Wrappers.lambdaQuery(LinkGroupDO.class).eq(LinkGroupDO::getAccountNo, accountNo));
    }

    @Override
    public int updateGroupById(LinkGroupDO linkGroupDO, long accountNo) {
        return linkGroupMapper.update(linkGroupDO, Wrappers.lambdaQuery(LinkGroupDO.class).eq(LinkGroupDO::getId, linkGroupDO.getId()).eq(LinkGroupDO::getAccountNo, accountNo));
    }
}
